package com.wl156.adapters;

import org.ksoap2.serialization.SoapObject;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wl156.R;

public class MyTruckMessageAdapter extends CheckableAdapter implements
		OnClickListener {

	public MyTruckMessageAdapter(Context context, SoapObject data) {
		mInflater = LayoutInflater.from(context);
		mData = data;
		mContext = context;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_mytruck_message, null);
		}

		// 04-25 23:30:10.996: D/(19800): result:
		// anyType{ArrayOfString=anyType{string=粤C76534; string=其它; string=21;
		// string=121; string=何生; string=1345667881; string=null; }; }, type:
		// SoapObject
		//顺序是：id, 车片号，车型，吨位，车长，联系人，联系电话，货运需求

		try {
			TextView carCode = (TextView) convertView.findViewById(R.id.carCode);
			TextView carType = (TextView) convertView.findViewById(R.id.carType);
			TextView catWeight = (TextView) convertView
					.findViewById(R.id.catWeight);
			
			TextView carLength = (TextView) convertView.findViewById(R.id.carLength);
			TextView contact = (TextView) convertView
					.findViewById(R.id.contact);
			TextView need = (TextView) convertView
					.findViewById(R.id.need);

			TextView phoneDial = (TextView) convertView.findViewById(R.id.dial);
			phoneDial.setOnClickListener(this);

			setTextViewStringFromProperty(position, carCode, 1);
			setTextViewStringFromProperty(position, carType, 2);
			setTextViewStringFromProperty(position, catWeight, 3);
			setTextViewStringFromProperty(position, carLength, 4);
			setTextViewStringFromProperty(position, contact, 5);
			setTextViewStringFromProperty(position, need, 7);
			setPhoneView(position, phoneDial, 6);
		} catch (Exception e) {
		}

		super.getView(position, convertView, parent);

		return convertView;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dial:
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.parse("tel:" + v.getTag().toString()));
			mContext.startActivity(i);
			break;
		}
	}
}
